package com.leetcode.algorithm.y22.m07;

import com.leetcode.algorithm.common.ListNode;

/**
 * 876. 链表的中间结点
 * 
 * https://leetcode.cn/problems/middle-of-the-linked-list/
 * 
 * @author jie.deng
 *
 */
public class Question0876Solution01 {

	public ListNode middleNode(ListNode head) {
		ListNode sentinel = new ListNode(0);
		sentinel.next = head;
		ListNode fast = sentinel;
		ListNode slow = sentinel;
		while (fast.next != null) {
			fast = fast.next;
			if (fast.next != null) {
				fast = fast.next;
				slow = slow.next;
			}
		}
		return slow.next;
	}
    
}
